/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: EditAcademicProgramView.java
 * Date: 10/03/2011
 */

package com.ingenius.sau.client.view;

import java.util.List;

import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.ingenius.sau.client.presenter.EditAcademicProgramPresenter.EditAcademicProgramDisplay;
import com.ingenius.sau.client.view.widgets.ListBox;

/**
 * Class <strong>EditAcademicProgramView</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
public class EditAcademicProgramView extends AbstractEditView implements
		EditAcademicProgramDisplay {

	// UI Widgets
	private final TextField<String> textCode;
	private final TextField<String> textName;
	private final TextField<String> textTitleGranted;
	private final TextField<String> textDuration;
	private final TextArea textMission;
	private final TextArea textVision;
	private final ListBox comboModality;

	// Constructor

	public EditAcademicProgramView() {
		super();
		textCode = new TextField<String>();
		textName = new TextField<String>();
		textTitleGranted = new TextField<String>();
		textDuration = new TextField<String>();
		textMission = new TextArea();
		textVision = new TextArea();
		comboModality = new ListBox();

		// TODO i18n
		setHeading("Edit Academic Program");
		setSize(500, 510);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ingenius.sau.client.view.AbstractEditView#createComponents()
	 */
	@Override
	protected void createComponents() {
		// TODO i18n
		FormData formData = new FormData("-20");

		textCode.setFieldLabel("Code");
		textCode.setAllowBlank(false);
		textCode.addPlugin(plugin);
		textCode.setData("text", "Enter the SNIES program code");
		textCode.getMessages().setBlankText("Code is required");

		textName.setFieldLabel("Name");
		textName.setAllowBlank(false);
		textName.addPlugin(plugin);
		textName.setData("text", "Enter the program name");
		textName.getMessages().setBlankText("Name is required");

		textMission.setFieldLabel("Mission");
		textMission.setHeight(75);
		textMission.setAllowBlank(false);
		textMission.addPlugin(plugin);
		textMission.setData("text", "Enter the program mission");
		textMission.getMessages().setBlankText("Mission is required");

		textVision.setFieldLabel("Vision");
		textVision.setHeight(75);
		textVision.setAllowBlank(false);
		textVision.addPlugin(plugin);
		textVision.setData("text", "Enter the program vision");
		textVision.getMessages().setBlankText("Vision is required");

		textTitleGranted.setFieldLabel("Title granted");
		textTitleGranted.setAllowBlank(false);
		textTitleGranted.addPlugin(plugin);
		textTitleGranted.setData("text", "Enter the program title granted");
		textTitleGranted.getMessages().setBlankText("This field is required");

		textDuration.setFieldLabel("Duration");
		textDuration.setAllowBlank(false);
		textDuration.addPlugin(plugin);
		textDuration.setData("text", "Enter the program duration (semesters)");
		textDuration.getMessages().setBlankText("Duration is required");

		comboModality.setFieldLabel("Modality");
		comboModality.setAllowBlank(false);
		comboModality.setEditable(false);
		comboModality.addPlugin(plugin);
		comboModality.setData("text", "Select the program modality");
		comboModality.getMessages().setBlankText("Modality is required");

		form.add(textCode, formData);
		form.add(textName, formData);
		form.add(textMission, formData);
		form.add(textVision, formData);
		form.add(textTitleGranted, formData);
		form.add(textDuration, formData);
		form.add(comboModality, formData);

	}

	@Override
	public String getCode() {
		return textCode.getValue();
	}

	@Override
	public void setCode(String code) {
		textCode.setValue(code);
	}

	@Override
	public String getName() {
		return textName.getValue();
	}

	@Override
	public void setName(String name) {
		textName.setValue(name);
	}

	@Override
	public String getMission() {
		return textMission.getValue();
	}

	@Override
	public void setMission(String mission) {
		textMission.setValue(mission);
	}

	@Override
	public String getVision() {
		return textVision.getValue();
	}

	@Override
	public void setVision(String vision) {
		textVision.setValue(vision);
	}

	@Override
	public String getTitleGranted() {
		return textTitleGranted.getValue();
	}

	@Override
	public void setTitleGranted(String titleGranted) {
		textTitleGranted.setValue(titleGranted);
	}

	@Override
	public String getModality() {
		return comboModality.getSimpleValue();
	}

	@Override
	public void setModality(String modality) {
		comboModality.setSimpleValue(modality);
	}

	@Override
	public void setModalities(List<String> modalities) {
		for (String modality : modalities) {
			// TODO i18n 2º column
			comboModality.add(modality, modality);
		}
	}

	@Override
	public Integer getDuration() {
		return Integer.parseInt(textDuration.getValue());
	}

	@Override
	public void setDuration(Integer duration) {
		textDuration.setValue(duration.toString());
	}

}
